package com.yin.myproject.arithmetic;

import java.util.Arrays;

/**
 * @author Eason
 * @create 2018-04-20 9:47
 **/
public class StraightInsertionSorter {
    public static void main(String[] args) {
        int array[] = {94, 12, 34, 76, 26, 9, 0, 37, 55, 76, 37, 5, 68, 83, 90, 37, 12, 65, 76, 49};
        StraightInsertionSorter sorter = new StraightInsertionSorter();
        int[] sort = sorter.sort(array);
        System.out.println(Arrays.toString(sort));
    }

    public int[] sort(int[] array) {
        int temp;
        for (int i = 1; i < array.length; i++) {
            temp = array[i];
            int j = i - 1;
            while (j >= 0 && temp < array[j]) {
                array[j + 1] = array[j];
                j--;
            }
            array[j + 1] = temp;
        }
        return array;
    }
}
